package cn.xk.ymcc.web.controller;

import cn.xk.ymcc.domain.dto.SendSmsDto;
import cn.xk.ymcc.result.JSONResult;
import cn.xk.ymcc.service.IVerifyCodeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/verifycode")
public class SmsController {

    @Autowired
    private IVerifyCodeService codeService;

    @PostMapping("/sendSmsCode")
    public JSONResult sendSms(@RequestBody @Valid SendSmsDto dto) {
        /*
            验证码的逻辑
         */
        codeService.sendCode(dto);


        return JSONResult.success();
    }

    @GetMapping("/imageCode/{key}")
    public JSONResult getImageCode(@PathVariable("key") String key) {

        String base64Str = codeService.getImageCode(key);
        return JSONResult.success(base64Str);


    }


}